package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 插入菜品主体数据
     * @param
     */
    @AutoFill(value = OperationType.INSERT)
    Long insert(Dish dish);

    /**
     * 插入菜品口味数据
     * @param flavors
     */
    void insertFlavors(List<DishFlavor> flavors);

    /**
     * 分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);
    
    
    @Select("select * from dish_flavor where dish_id = #{id};")
    List<DishFlavor> getByIdWithFlavor(Long id);

    /**
     * 新增员工中的修改员工数据 有数据就修改
     * @param dishDTO
     */
    void updateById(DishDTO dishDTO);

    /**
     * 删除所有的菜品口味数据
     * @param id
     */
    @Delete("delete from dish_flavor where dish_id = #{id}")
    void deleteByIdWithFlavor(Long id);


    @Select("select * from dish where category_id = #{categoryId} and status = 1")
    List<DishDTO> list(Integer categoryId);

    /**
     * 根据Id查询菜品数据
     * @param categoryId
     * @return
     */

    List<Dish> listBaseinfo(Long categoryId);


    /**
     * 根据id查询菜品口味数据
     * @param id
     * @return
     */
    @Select("select * from dish_flavor where dish_id = #{id};")
    List<DishFlavor> getByDishId(Long id);


    @Update("update dish set status = #{status} where id = #{id}")
    void startorstop(Integer status, Long id);
}
